<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 验证数字
 * @param mixed $value
 * @param integer $min
 * @param integer $max
 * @return mixed 如果成功，则返回被过滤的数据。如果失败，则返回 FALSE。
 * 
 */
function xsfn_validate_int($value, $minrange = 0, $maxrange = 0) {
    $options = [];
    if ($minrange != 0 && $maxrange != 0) {
        $options = ['min_range' => $minrange, 'max_range' => $maxrange];
    }
    return filter_var($value, FILTER_VALIDATE_INT, $options);
}

function xsfn_validate_string($value, $minlen, $maxlen) {
    $len = strlen($value);
    return ($len > $minlen && $len < $maxlen);
}

function xsfn_base64_decode($value) {
    $value = iconv("latin1", "UTF-8", $value);
    $value = base64_decode($value);
    return $value;
}
